﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SmartSpace.Cwt;

namespace WebApp.Management.Categories
{
    public partial class List : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ICwtService service = Global.Get<ICwtService>();
                this._ctlRepeater.DataSource = service.FindCategories();
                this._ctlRepeater.DataBind();
            }
        }

        protected void _ctlBtnSave_Click(object sender, EventArgs e)
        {
            string caption = _ctlEditCaption.Text;
            string code = _ctlEditCode.Text;

            ICwtService service = Global.Get<ICwtService>();
            Category category = new Category();
            category.Id = Guid.NewGuid();
            category.Code = code;
            category.Caption = caption;

            if (service.SaveCategory(category))
            {
                Response.Redirect("./List.aspx");
            }
            else
            {
                Response.Redirect("../Message.aspx");
            }
        }
    }
}